Imports Janus.Windows.GridEX
Public Class frmRESERVATION_DETAIL
    Dim Res_Date As Date
    Dim CUS_CODE As String = ""
    Dim index As Integer = 1
    Dim tbls As String = ""
    Public ID As Integer = 0

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub btnDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDate.Click
        Dim frm As New frmCalendar
        frm.ShowDialog()
        Res_Date = frm.Calendar2.SelectionRange.Start
        txtRes_Date.Text = Res_Date.ToString(PublicVariable.DateTimeFormat)
    End Sub

    Private Sub btnTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTime.Click
        Dim frm As New frmTime
        frm.ShowDialog()
        txtTime.Text = frm.txtHour.Text + ":" + frm.txtMinute.Text
    End Sub

    Private Sub btnCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomer.Click
        Dim frm As New frmSEARCH_CUSTOMER
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtCustomerName.Text = frm.GridCustomer.GetValue("CUS_NAME").ToString
            txtPhone.Text = frm.GridCustomer.GetValue("PHONE").ToString
            CUS_CODE = frm.GridCustomer.GetValue("CUS_CODE").ToString
        End If
    End Sub

    Private Sub txtDeposit_ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDeposit.ButtonClick
        PublicVariable.frmCalculator.Top = txtDeposit.Top + txtDeposit.Height
        PublicVariable.frmCalculator.Left = txtDeposit.Left + txtDeposit.Width
        If PublicVariable.frmCalculator.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtDeposit.Text = String.Format(PublicVariable.NumberFormatString, PublicVariable.frmCalculator.txtResult.Text)
        End If
    End Sub

    Private Sub txtCustomerName_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerName.Enter
        index = 1
    End Sub

    Private Sub txtPhone_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPhone.Enter
        index = 2
    End Sub

    Private Sub txtRemark_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
        index = 3
    End Sub

    Private Sub Keyboardcontrol1_UserKeyPressed(ByVal sender As System.Object, ByVal e As VINAPOS.KeyboardClassLibrarySmall.KeyboardEventArgs) Handles Keyboardcontrol1.UserKeyPressed
        Select Case index
            Case 1
                txtCustomerName.Focus()
            Case 2
                txtPhone.Focus()
            Case 3
                txtRemark.Focus()
        End Select
        SendKeys.Send(e.KeyboardKeyPressed)
    End Sub

    Private Sub frmRESERVATION_DETAIL_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmRESERVATION_DETAIL_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunction.NewFormLoad(Me)
        Dim arName As New ArrayList
        arName.Add("@FL_CODE")
        arName.Add("@DATE")
        Dim arVal As New ArrayList
        arVal.Add("")
        arVal.Add(PublicVariable.SystemDate)
        GridTable.DataSource = BLL.ObjectGetBy("TABLES_LOADBYFLOOR", arName, arVal)
        GridTable.CollapseGroups()
        If ID > 0 Then
            arName.Clear()
            arName.Add("@ID")
            arVal.Clear()
            arVal.Add(ID)
            Dim dt As DataTable = BLL.ObjectGetBy("RESERVATION_LOAD", arName, arVal)
            If dt.Rows.Count > 0 Then
                txtCustomerName.Text = dt.Rows(0).Item("CUS_NAME").ToString
                CUS_CODE = dt.Rows(0).Item("CUS_CODE").ToString
                txtPhone.Text = dt.Rows(0).Item("CUS_PHONE").ToString
                Res_Date = dt.Rows(0).Item("RES_DATE")
                txtRes_Date.Text = String.Format(PublicVariable.SystemDateFormat, Res_Date)
                txtTime.Text = dt.Rows(0).Item("RES_TIME").ToString
                txtRemark.Text = dt.Rows(0).Item("REMARK").ToString
                tbls = dt.Rows(0).Item("RES_TABLE").ToString
                txtDeposit.Text = String.Format(PublicVariable.NumberFormatString, dt.Rows(0).Item("RES_DEPOSIT"))
                txtGuest.Text = String.Format(PublicVariable.NumberFormatString, dt.Rows(0).Item("RES_GUEST"))
                txtTable.Text = ""
                For i As Integer = 0 To dt.Rows.Count - 1
                    txtTable.Text = txtTable.Text & dt.Rows(i).Item("TBL_Name").ToString & ","
                    If GridTable.FindAll(GridTable.RootTable.Columns("TBL_CODE"), ConditionOperator.Equal, dt.Rows(i).Item("TBL_Code").ToString) Then
                        GridTable.SetValue("CK", True)
                    End If
                Next
            End If
        End If
       
    End Sub



    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtCustomerName.Text = "" Then
            SystemFunction.ShowMessageForm("PLEASE INPUT CUSTOMER NAME!", "")
        Else
            If ID > 0 Then
                'UPDATE

            Else
                'ADD NEW
                Dim Deposit As Double = 0
                If IsNumeric(txtDeposit.Text) Then
                    Deposit = CDbl(txtDeposit.Text)
                Else
                    Deposit = 0
                End If
                Dim Guest As Double = 0
                If IsNumeric(txtGuest.Text) Then
                    Guest = CDbl(txtGuest.Text)
                Else
                    Guest = 0
                End If
                Dim dt As DataTable
                Dim arName As New ArrayList
                Dim arVal As New ArrayList
                arName.Clear()
                arName.Add("@CUS_CODE")
                arName.Add("@CUS_NAME")
                arName.Add("@CUS_PHONE")
                arName.Add("@RES_DATE")
                arName.Add("@RES_TIME")
                arName.Add("@RES_DEPOSIT")
                arName.Add("@RES_GUEST")
                arName.Add("@RES_TABLE")
                arName.Add("@REMARK")
                arName.Add("@CREATEDUSER")
                arVal.Clear()
                arVal.Add(CUS_CODE)
                arVal.Add(txtCustomerName.Text)
                arVal.Add(txtPhone.Text)
                arVal.Add(Res_Date)
                arVal.Add(txtTime.Text)
                arVal.Add(Deposit)
                arVal.Add(Guest)
                arVal.Add(tbls)
                arVal.Add(txtRemark.Text)
                arVal.Add(PublicVariable.UserCode)
                dt = BLL.ObjectGetBy("RESERVATION_ADD", arName, arVal)
                If dt.Rows.Count > 0 Then
                    'BLL.ReturnXML("RESERVATION", dt)
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                Else
                    SystemFunction.ShowMessageForm("SAVE FAILED!", "")
                End If
            End If
            
        End If
    End Sub

    Private Sub txtGuest_ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGuest.ButtonClick
        Dim frm As New frmNUMBER
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtGuest.Text = String.Format(PublicVariable.NumberFormatString, frm.txtNumber.Text)
        End If
    End Sub

 

    Private Sub GridTable_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridTable.Click
        txtTable.Text = ""
        tbls = ""
        For Each row As GridEXRow In Me.GridTable.GetCheckedRows
            tbls = tbls + row.Cells("TBL_CODE").Value + ","
            txtTable.Text = txtTable.Text & row.Cells("TBL_NAME").Value + ","
        Next
    End Sub
End Class